package com.bdqn.struts.interceptor;

import com.bdqn.struts.entity.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

public class AuthorizationInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        Map session=actionInvocation.getInvocationContext().getSession();
        session.put("login",new User());
        User user=(User) session.get("login");
        if (user==null){
            System.out.println("拦截器判断用户没有登录!!!!");
            return Action.LOGIN;
        }else {
            //执行后续的拦截器或者action
            return actionInvocation.invoke();
        }
    }
}
